﻿/*
****************************************************************************************************************
*= = 版权信息：Copyright (C) 356 - 999. Ombres Industry Empiral. All rights reserved.
*= = 文件名称：Dwarf.cxx
*= = 功能描述：风之谷配置工具定义主文件
*= = 编写人员：Carlyon W. Tung
****************************************************************************************************************
*/

/*
*===============================================================================================================
*= = 声明文件
*===============================================================================================================
*/

#ifndef WXUSINGDLL
#define WXUSINGDLL
#endif // !WXUSINGDLL

#include <wx/wxprec.h>

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include <wx/apptrait.h>
#include <wx/datetime.h>
#include <wx/filename.h>
#include <wx/image.h>
#include <wx/bookctrl.h>
#include <wx/artprov.h>
#include <wx/imaglist.h>
#include <wx/minifram.h>
#include <wx/sysopt.h>
#include <wx/notifmsg.h>
#include <wx/generic/notifmsg.h>
#include <wx/modalhook.h>

#if defined(__WXMSW__) && wxUSE_TASKBARICON
#include <wx/taskbar.h>
#endif

#if wxUSE_RICHMSGDLG
#include <wx/richmsgdlg.h>
#endif // wxUSE_RICHMSGDLG

#if wxUSE_COLOURDLG
#include <wx/colordlg.h>
#endif // wxUSE_COLOURDLG

#if wxUSE_CHOICEDLG
#include <wx/choicdlg.h>
#endif // wxUSE_CHOICEDLG

#include <wx/rearrangectrl.h>
#include <wx/addremovectrl.h>

#if wxUSE_STARTUP_TIPS
#include <wx/tipdlg.h>
#endif // wxUSE_STARTUP_TIPS

#if wxUSE_TIPWINDOW
#include <wx/tipwin.h>
#endif // wxUSE_TIPWINDOW

#if wxUSE_PROGRESSDLG
#if wxUSE_STOPWATCH && wxUSE_LONGLONG
#include <wx/datetime.h>
#endif

#include <wx/progdlg.h>
#endif // wxUSE_PROGRESSDLG

#include <wx/appprogress.h>

#if wxUSE_ABOUTDLG
#include <wx/aboutdlg.h>

// these headers are only needed for custom about dialog
#include <wx/statline.h>
#include <wx/generic/aboutdlgg.h>
#endif // wxUSE_ABOUTDLG

#if wxUSE_BUSYINFO
#include <wx/busyinfo.h>
#endif // wxUSE_BUSYINFO

#if wxUSE_NUMBERDLG
#include <wx/numdlg.h>
#endif // wxUSE_NUMBERDLG

#if wxUSE_FILEDLG
#include <wx/filedlg.h>
#include <wx/filedlgcustomize.h>
#endif // wxUSE_FILEDLG

#if wxUSE_DIRDLG
#include <wx/dirdlg.h>
#endif // wxUSE_DIRDLG

#if wxUSE_FONTDLG
#include <wx/fontdlg.h>
#endif // wxUSE_FONTDLG

#if wxUSE_FINDREPLDLG
#include <wx/fdrepdlg.h>
#endif // wxUSE_FINDREPLDLG

#if wxUSE_INFOBAR
#include <wx/infobar.h>
#endif // wxUSE_INFOBAR

#include <wx/spinctrl.h>
#include <wx/propdlg.h>
#include <wx/valgen.h>

#include "Dwarf.h"

#if wxUSE_CREDENTIALDLG
#include <wx/creddlg.h>
#endif

#if USE_COLOURDLG_GENERIC
#include <wx/generic/colrdlgg.h>
#endif // USE_COLOURDLG_GENERIC

#if USE_DIRDLG_GENERIC
#include <wx/generic/dirdlgg.h>
#endif // USE_DIRDLG_GENERIC

#if USE_FILEDLG_GENERIC
#include <wx/generic/filedlgg.h>
#endif // USE_FILEDLG_GENERIC

#if USE_FONTDLG_GENERIC
#include <wx/generic/fontdlgg.h>
#endif // USE_FONTDLG_GENERIC

#include <cstdio>
#include <iostream>
#include <string>

#include "AboutDlg.h"

/*
*===============================================================================================================
*= = 预处理声明
*===============================================================================================================
*/

#ifdef HAVE_CONFIG_H
    #include <config.h>
#endif // End of HAVE_CONFIG_H

/*
*===============================================================================================================
*= = 宏定义
*===============================================================================================================
*/

#define COPYRIGHT "Copyright (C) 356 - 999. Ombres Industry Empiral. All rights reserved."
#define DFVERSION "Dwarf 1.0.1 - 365"
#define DFAUTHORS "Carlyon W. Tung    loongs@syuusui.com"

/*
*===============================================================================================================
*= = 命名空间
*===============================================================================================================
*/

using namespace std;

/*
*===============================================================================================================
*= = 全局变量
*===============================================================================================================
*/

wxIMPLEMENT_APP(DwarfApp);

/*
*===============================================================================================================
*= = 类函数定义
*===============================================================================================================
*/

bool DwarfApp::OnInit()
{
    wxLog::SetLogLevel(wxLOG_Info);

    m_checker = new wxSingleInstanceChecker("DwarfApp");

    if (m_checker->IsAnotherRunning())
    {
        wxOperatingSystemId os = wxGetOsVersion();

        if (os == wxOS_WINDOWS_NT)
        {

#ifdef __INSIGHT_OS_WINDOWS__
            HWND hWnd = FindWindow(NULL, wxT("Dwarf - 风之谷配置工具"));
            if (NULL != hWnd)
            {
                ShowWindow(hWnd, SW_RESTORE);
                SetForegroundWindow(hWnd);
                SendMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
            }
#endif // __INSIGHT_OS_WINDOWS__

        }
        else
        {
            wxLogInfo(wxT("Another program instance is already running, aborting!"));
        }

        delete m_checker;
        m_checker = nullptr;

        return false;
    }

    wxLocale locale(wxLANGUAGE_CHINESE_CHINA);

    locale.AddCatalogLookupPathPrefix(wxT("."));
    locale.AddCatalog(wxT("DwarfApp"));

    DwarfFrame *dwarf = new DwarfFrame();
    dwarf->Show(true);

    return true;
}

int DwarfApp::OnExit()
{
    delete m_checker;

    return 0;
}

DwarfFrame::DwarfFrame() : wxFrame(nullptr, wxID_ANY, wxT("Dwarf - 风之谷配置工具"), wxDefaultPosition, wxSize(800, 600))
{

#ifdef __INSIGHT_OS_WINDOWS__
    this->SetIcon(wxIcon("IDI_DWARF"));
#endif // __INSIGHT_OS_WINDOWS__

    this->Maximize();

    // 绘制程序菜单
    wxMenu *menuFile = new wxMenu;
    menuFile->Append(ID_CHANGEPASSWORD, wxT("&修改密码\tCtrl-P"), "Help string shown in status bar for this menu item.");
    menuFile->AppendSeparator();
    menuFile->Append(wxID_EXIT, wxT("&退出"));

    wxMenu* menuView = new wxMenu;
    menuView->Append(wxID_ABOUT);

    wxMenu* menuTool = new wxMenu;
    menuTool->Append(wxID_ABOUT);

    wxMenu* menuExtend = new wxMenu;
    menuExtend->Append(wxID_ABOUT);

    wxMenu* menuHelp = new wxMenu;
    menuHelp->Append(wxID_ABOUT, wxT("&关于"));

    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append(menuFile, wxT("&文件(F)"));
    menuBar->Append(menuView, wxT("&视图(V)"));
    menuBar->Append(menuTool, wxT("&工具(T)"));
    menuBar->Append(menuExtend, wxT("&扩展(E)"));
    menuBar->Append(menuHelp, wxT("&帮助(H)"));

    SetMenuBar(menuBar);

    // 绘制程序工具栏
    wxToolBar* toolbar = CreateToolBar();

    toolbar->Realize();

    SetToolBar(toolbar);

    // 绘制程序工程管理器
    m_pAM_ProMgrView = new wxAuiManager(this);
    wxColour bgColor = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);

    wxPanel* leftPanel = new wxPanel(this);
    leftPanel->SetBackgroundColour(bgColor);

    wxPanel* rightPanel = new wxPanel(this);
    rightPanel->SetBackgroundColour(bgColor);

    wxAuiPaneInfo leftPaneInfo;
    leftPaneInfo.Caption(wxT("工程管理器\n")).Left().BestSize(280, -1);
    leftPanel->SetExtraStyle(GetExtraStyle() | wxFRAME_EX_CONTEXTHELP);
    m_pAM_ProMgrView->AddPane(leftPanel, leftPaneInfo);

    wxAuiPaneInfo rightPaneInfo;
    rightPaneInfo.Caption(wxT("资源管理器")).Right().BestSize(280, -1);
    m_pAM_ProMgrView->AddPane(rightPanel, rightPaneInfo);

    m_pAM_ProMgrView->Update();

    // 绘制程序状态栏
    this->CreateStatusBar();
    SetStatusText("Welcome to Vulgaris of the Valley of the Wind!");

    // 各类控件绑定程序事件
    Bind(wxEVT_MENU, &DwarfFrame::OnChangePassword, this, ID_CHANGEPASSWORD);
    Bind(wxEVT_MENU, &DwarfFrame::OnAbout, this, wxID_ABOUT);
    Bind(wxEVT_MENU, &DwarfFrame::OnExit, this, wxID_EXIT);
}

void DwarfFrame::OnExit(wxCommandEvent& event)
{
    Close(true);
}

void DwarfFrame::OnAbout(wxCommandEvent& event)
{
    wxMessageBox("This is a Tools of the Windurb with wxWidgets.", wxT("关于 Dwarf"), wxOK | wxICON_INFORMATION);
}

void DwarfFrame::OnChangePassword(wxCommandEvent& event)
{
    wxLogMessage("Dwarf from wxWidgets!");
}


/*
****************************************************************************************************************
*= = 文件结束
****************************************************************************************************************
*/


